from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import Unicode

from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker

from zope.sqlalchemy import ZopeTransactionExtension

from sqlalchemy import Text

from sqlalchemy import Table, ForeignKey
from sqlalchemy.orm import relationship, backref

from scp.modelo.models import Base

from scp.modelo.Tipo_Item import Tipo_Item

__all__ = [ 'Fase' ]


association_table = Table('fase_tipo_item', Base.metadata,
    Column('fase_id', Integer, ForeignKey('fase.id')),
    Column('tipo_item_id', Integer, ForeignKey('tipo_item.id'))
)


class Fase(Base):
    """ The SQLAlchemy declarative model class for a Page object. """
    __tablename__ = 'fase'
    id = Column(Integer, primary_key=True)
    nombre = Column(Unicode(20), nullable=False, unique=True)
    descripcion = Column(Unicode(100), nullable=False)
    fecha_inicio = Column(Text, nullable=False)
    fecha_fin = Column(Text, nullable=False)
    observacion = Column(Unicode(100), nullable=False)
    estado = Column(Unicode(20), nullable=False)
    tipos_items = relationship("Tipo_Item",
                    secondary=association_table)
